package com.example.no1admin.controller;

import com.example.no1admin.mapper.AlbumMapper;
import com.example.no1admin.mapper.PictureMapper;
import com.example.no1admin.pojo.dto.route.RouteAddNewDTO;

import com.example.no1admin.pojo.dto.route.RouteUpdateDTO;
import com.example.no1admin.pojo.entity.Album;
import com.example.no1admin.pojo.entity.Picture;
import com.example.no1admin.pojo.entity.Route;
import com.example.no1admin.pojo.vo.album.AlbumDetailVO;
import com.example.no1admin.pojo.vo.route.RouteListItemVO;
import com.example.no1admin.service.IRouteService;

import com.example.no1admin.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "拍摄路线管理模块")
@RequestMapping("/routes")
@Slf4j
@RestController
public class RouteController {
    @Autowired
    IRouteService routeService;

    @ApiOperation("添加拍摄路线")
    @PreAuthorize("hasAuthority('ROLE_admin')")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult addNew(@RequestBody RouteAddNewDTO routeAddNewDTO){
        log.debug("接受到的请求参数:{}",routeAddNewDTO);
        routeService.addNew(routeAddNewDTO);
        return JsonResult.ok();
    }
    @ApiOperation("删除拍摄路线")
    @PreAuthorize("hasAuthority('ROLE_admin')")
    @ApiOperationSupport(order = 300)
    @PostMapping("/{id:[0-9]+}/delete-by-id")
    public JsonResult delete(@PathVariable Long id){
        routeService.deleteById(id);
        return JsonResult.ok();
    }

    @ApiOperation("修改拍摄路线状态")
    @ApiOperationSupport(order = 400)
    @PostMapping("/update-enable-by-id")
    public JsonResult updateEnable(@RequestBody RouteUpdateDTO routeUpdateDTO){
        routeService.updateById(routeUpdateDTO);
        return JsonResult.ok();
    }

    @ApiOperation("拍摄路线列表")
    @ApiOperationSupport(order = 200)
    @GetMapping("")
    public JsonResult list(){
        log.debug("接收到查询拍摄路线列表的请求");
        List<RouteListItemVO> styles = routeService.list();
        return JsonResult.ok(styles);
    }


}
